package com.wkhyapp.lm.contract;
import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.AddGoodsRequest;
import com.wkhyapp.lm.http.net.GrabAlbumRequest;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.utils.MemberUtils;

/**
 * Created by fang on 2021/10/24.
 */

public class GrabAlbumPresenter extends BasePresenter<GrabAlbumView> {

    public GrabAlbumPresenter(GrabAlbumView grabAlbumView) {
        super(grabAlbumView);
    }

    public void getData(String url){
        GrabAlbumRequest request = new GrabAlbumRequest();
        request.setUserId(MemberUtils.getUid());
        request.setPageNo(1);
        request.setPageSize(20);
        request.setUrl(url);
        addSubscription(apiStores.grabAlbum(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoods(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }


    public void getDataMore(int pageNo,String url){
        GrabAlbumRequest request = new GrabAlbumRequest();
        request.setUserId(MemberUtils.getUid());
        request.setPageNo(pageNo);
        request.setPageSize(20);
        request.setUrl(url);
        addSubscription(apiStores.grabAlbum(request),new ApiCallback<SuperResponse<Goods>>() {
            @Override
            public void onSuccess(SuperResponse<Goods> response) {
                mvpView.setGoodsMore(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }


    public void  upload(AddGoodsRequest addGoodsRequest){
        addSubscription(apiStores.addGoodsForGrab(addGoodsRequest),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.upLoadSucc();
            }
            @Override
            public void onFailure(String msg) {
                mvpView.dismissLoad();
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

}
